package com.koron.css2.serviceManage.impl;

import com.koron.css2.ApplicationConfig;
import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.TWaterCompanyNameListBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.mapper.TWaterCompanyMapper;
import com.koron.util.Constant;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.Iterator;
import java.util.List;

/**
 * 查询所有水司名称和编号
 *
 * @author 李攀
 */
public class CompanyNameList implements ServerInterface {

    private static Logger logger = LogManager.getLogger(CompanyNameList.class);
    //过滤集团总部的水司code
//    private static List<String> companyNos = Arrays.asList("00", ApplicationConfig.getWaterCodeFilter(), ApplicationConfig.getWaterCodeFilter());

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {

        @SuppressWarnings("rawtypes")
        MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", List.class);

        try {
            TWaterCompanyMapper mapper = factory.getMapper(TWaterCompanyMapper.class);
            List<TWaterCompanyNameListBean> list = mapper.selectCompanyName();
            //过滤掉集团总部
            Iterator<TWaterCompanyNameListBean> it = list.iterator();
            while (it.hasNext()) {
                TWaterCompanyNameListBean userObj = it.next();

                if (userObj.getCompanyNo().equals(ApplicationConfig.getWaterCodeFilter()) ) {
                    it.remove();
                }
            }
            info.setData(list);
        } catch (Exception e) {
            info.setCode(Constant.MESSAGE_INT_FAIL);
            info.setDescription(e.getMessage());
            logger.error(e.getMessage(), e);
        }
        return info;
    }


}
